package org.wk.affiliate.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.wk.affiliate.domain.NoticeManage;
import org.wk.affiliate.service.NoticeService;
import org.wk.affiliate.view.NoticeVo;
import org.wk.core.common.view.PageVo;
import org.wk.core.common.view.ResponseVo;

import java.util.Map;

/**
 * @author TangShenShen
 * @Description: 公告管理controller类  (App端)
 * @date 2018/6/813:59
 */
@Controller
public class AppNoticeController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private NoticeService noticeService;

    /**
     * 手机端  鲸拍公告列表
     * @param page_num
     * @param page_size
     * @return
     */
    @RequestMapping(value="notice",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String noticeList(@RequestParam(required = false,defaultValue = "1") Integer page_num, @RequestParam(required = false,defaultValue = "15") Integer page_size) {
        logger.info("鲸拍公告列表>>>>{}");
        ResponseVo responseVo = noticeService.findByPage(page_num,page_size);
        logger.info("鲸拍公告列表返回值>>>>{}",responseVo.toString());
        return responseVo.toString();
    }

    @RequestMapping(value="notice/info/{noticeId}",method = RequestMethod.GET,produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String save(@PathVariable String noticeId, ModelMap modelMap) {
        NoticeManage notice = noticeService.selectByIdForApp(noticeId);
        modelMap.put("notice",notice);
        return "notice/detail";
    }

    /**
     * 获取最新公告
     * @return
     */
    @RequestMapping(value="notice/newNotice")
    @ResponseBody
    public ResponseVo newNotice() {
        NoticeManage notice = noticeService.getNewNotice();
        return ResponseVo.success().setData(notice);
    }


}
